package com.jiandan.business.web;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jiandan.base.entity.ExtData;
import com.jiandan.base.mapper.JsonMapper;
import com.jiandan.base.utils.ExtDataUtil;
import com.jiandan.business.entity.Staff;
import com.jiandan.business.service.StaffService;
import com.jiandan.business.util.CemeteryContants;

@Controller
@RequestMapping(value = "/staff")
public class StaffController {
	
	private static final Logger logger = Logger.getLogger(StaffController.class);

	@Autowired
	private StaffService staffService;
	
	
	@RequestMapping(value = "login")
	@ResponseBody
	public String userLogin(ServletRequest request, Staff staff) {
		ExtData<Staff> extData = null;
		if(staff.getName() != null && staff.getPassword() != null){
			if(staffService.validStaff(staff)){
				extData = ExtDataUtil.genWithSingleData(staff);
			}else{
				extData = ExtDataUtil.genWithErrors("用户名密码错误");
			}
		}
		String resData = JsonMapper.nonEmptyMapper().toJsonP(request.getParameter("callback"), extData);
		logger.info("登陆返回的JSON字符串:" + resData);
		return resData;
	}
	
	
	
}
